/*
 * SSD1289.h
 *
 * Created: 2012-05-28 22:33:17
 *  Author: Sebastian_2
 */ 


#ifndef SSD1289_H_
#define SSD1289_H_

#include "../DataTypes.h"
#include "../conf.h"
#include "../Colours.h"
#include "../fonts/fonts.h"

#ifndef ATMEGA
#define CS_SET() SSD1289_CONFIG.OUTSET = SSD1289_CS_BIT
#define CS_CLR() SSD1289_CONFIG.OUTCLR = SSD1289_CS_BIT
#define RD_SET() SSD1289_CONFIG.OUTSET = SSD1289_RD_BIT
#define RD_CLR() SSD1289_CONFIG.OUTCLR = SSD1289_RD_BIT
#define RS_SET() SSD1289_CONFIG.OUTSET = SSD1289_RS_BIT
#define RS_CLR() SSD1289_CONFIG.OUTCLR = SSD1289_RS_BIT
#define WR_SET() SSD1289_CONFIG.OUTSET = SSD1289_WR_BIT
#define WR_CLR() SSD1289_CONFIG.OUTCLR = SSD1289_WR_BIT
#define SEND_LO(d) SSD1289_DATA_LO.OUT = d
#define SEND_HI(d) SSD1289_DATA_HI.OUT = d
#else
#define RS_SET() RS_PORT |= (1 << RS_BIT)
#define RS_CLR() RS_PORT &= ~(1 << RS_BIT)
#define WR_SET() WR_PORT |= (1 << WR_BIT)
#define WR_CLR() WR_PORT &= ~(1 << WR_BIT)
#define RD_SET() RD_PORT |= (1 << RD_BIT)
#define RD_CLR() RD_PORT &= ~(1 << RD_BIT)
#define CS_SET() CS_PORT |= (1 << CS_BIT)
#define CS_CLR() CS_PORT &= ~(1 << CS_BIT)
#define RESET_SET() RESET_PORT |= (1 << RESET_BIT)
#define RESET_CLR() RESET_PORT &= ~(1 << RESET_BIT)
#define LATCH_SET() LATCH_PORT |= (1 << LATCH_BIT)
#define LATCH_CLR() LATCH_PORT &= ~(1 << LATCH_BIT)
#define LED_SET() LED_PORT |= (1 << LED_BIT)
#define LED_CLR() LED_PORT &= ~(1 << LED_BIT)
#define SEND(x) DATA_PORT=x
#endif

#define SSD1289_MaxX 319
#define SSD1289_MaxY 239

#ifndef ATMEGA
#define SSD1289_WriteDataFast(d)	SEND_HI(d >> 8);\
									SEND_LO(d);\
									WR_CLR();\
									WR_SET();
#else
#define SSD1289_WriteDataFast(d)    SEND(d >> 8);\
									LATCH_SET();\
									LATCH_CLR();\
									SEND(d);\
									WR_CLR();\
									WR_SET();
#endif
#define SSD1289_Select() CS_CLR()
#define SSD1289_Deselect() CS_SET()

void SSD1289_Init();
void SSD1289_WriteCommand(uint8_t c);
void SSD1289_WriteData(uint16_t d);
void SSD1289_WriteRegister(uint8_t c, uint16_t d);

void SSD1289_SetCursor(point *p);
void SSD1289_SetPaintArea(point *start, point *stop);

void SSD1289_DrawRect(point *start, point *stop);
void SSD1289_DrawLineX(point *start, point *stop, uint8_t width);
void SSD1289_DrawLineY(point *start, point *stop, uint8_t width);
void SSD1289_Clear();

void SSD1289_DrawPixel(point *location);
point SSD1289_DrawChar(char c, point *location, const FONT_INFO *font);
point SSD1289_PrintString(char *c, point *location, const FONT_INFO *font);


#endif /* SSD1289_H_ */